<template>
	<view class="container">
		<view class="top">
			<view class="p-box">
				<image class="bg" :src="$img_path('/pagesMine/1.png')" mode="scaleToFill"></image>
				<view class="left">
					<view class="price">
						<text>￥</text>{{info.money}}
					</view>
					<view class="text">
						我的余额
					</view>
				</view>
				<view class="r-btn">
					<button @click="toRecharge">充值</button>
				</view>
			</view>

			<view class="tab">
				<view :class="['t-item', tab_index==0?'select':'']" @click="check(0)">
					<text>全部</text>
				</view>
				<view :class="['t-item', tab_index==2?'select':'']" @click="check(2)">
					<text>支出</text>
				</view>
				<view :class="['t-item', tab_index==1?'select':'']" @click="check(1)">
					<text>收入</text>
				</view>
			</view>
		</view>

		<view class="list" v-if="list.length>0">
			<letterSortView class="letterSortView" :list="list" :propsKey="{title:'date',data:'list'}" >
			</letterSortView>
		</view>
	</view>
</template>

<script>
	import { 
		initialWithdraw ,
		moneylog,
	} from '@/utils/api/userApi.js'
	import letterSortView from '@/components/letterSort/letterSortView.vue'
	import collapse from '../../components/collapse/collapse.vue';
	export default {
		components: {
			collapse,
			letterSortView
		},
		data() {
			return {
				tab_index: 0,
				listData:[
					{
						id:1,
						date:'2024-5',
						list:[]
					},
				],
				
				info:null,
				
				list:[],
				page:1,
				last_page:0,
				total:0,
			};
		},
		onLoad() {
			this.initialWithdraw()
			this.getmoneylog()
		},
		methods:{
			initialWithdraw(){
				initialWithdraw().then(res=>{
					// console.log(res,'--')
					this.info = res.data
				})
			},
			check(val){
				this.tab_index = val
				this.getmoneylog()
			},
			getmoneylog(){
				uni.showLoading({
					title:'加载中...'
				})
				moneylog({type:this.tab_index,page:this.page}).then(res=>{
					console.log(res,'--')
					if(this.page==1){
						this.list = res.data.data
					}else{
						this.list = [...this.list,...res.data.data]
					}
					this.total = res.data.total
					this.last_page = res.data.last_page
					uni.hideLoading()
				})
			},
			
			toRecharge(){
				uni.navigateTo({
					url:'/pagesMine/myWallet/recharge'
				})
			}
		}
	}
</script>
<style>
	page {
		background-color: #FFFFFF;
	}
</style>
<style lang="scss" scoped>
	.container {
		.top {
			padding: 20rpx 22rpx 0;
			box-sizing: border-box;

			.p-box {
				width: 100%;
				height: 228rpx;
				position: relative;
				padding: 50rpx 40rpx;
				box-sizing: border-box;
				display: flex;
				align-items: center;
				justify-content: space-between;

				&>image.bg {
					position: absolute;
					top: 0;
					left: 0;
					width: 100%;
					height: 100%;
					z-index: 0;
				}

				.left {
					position: relative;
					z-index: 1;

					.price {
						font-weight: 800;
						font-size: 60rpx;
						color: #FFFFFF;
						line-height: 84rpx;

						text {
							font-size: 30rpx;
						}
					}

					.text {
						font-weight: bold;
						font-size: 30rpx;
						color: #FFFFFF;
						line-height: 42rpx;
					}
				}

				.r-btn {
					position: relative;
					z-index: 1;

					button {
						width: 150rpx;
						height: 60rpx;
						background: #FFFFFF;
						border-radius: 30rpx;
						font-weight: bold;
						font-size: 28rpx;
						color: #E72A2A;
						line-height: 60rpx;
					}
				}
			}

			.tab {
				width: 100%;
				// height: 88rpx;
				background-color: #FFFFFF;
				display: flex;
				align-items: center;
				justify-content: center;
				padding: 40rpx 60rpx 34rpx;
				box-sizing: border-box;
				z-index: 5;

				.t-item {
					&:not(:first-child) {
						margin-left: 72rpx;
					}

					text {
						font-weight: 400;
						font-size: 30rpx;
						color: #999999;
						line-height: 42rpx;
					}

					&.select {
						text {
							color: #333333;
							position: relative;

							&::before {
								content: '';
								width: 60rpx;
								height: 4rpx;
								background: #E72A2A;
								border-radius: 2rpx;
								position: absolute;
								top: calc(100% + 10rpx);
								left: 50%;
								transform: translateX(-50%);
							}
						}
					}
				}
			}
		}

		.list {
			

			
		}
	}
</style>